package avicit.bdp.dgs.metadata.service;

import avicit.bdp.common.base.BaseService;
import avicit.bdp.common.dto.TaskInstanceDto;
import avicit.bdp.common.service.dao.BdpCommonDao;
import avicit.bdp.dgs.metadata.dao.MetadataCollectTaskResultDao;
import avicit.bdp.dgs.metadata.dto.MetadataCollectTaskResult;
import avicit.platform6.core.exception.BusinessException;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

@Service
public class MetadataCollectTaskResultService
    extends BaseService<MetadataCollectTaskResultDao, MetadataCollectTaskResult> {

  @Resource
  private  BdpCommonDao commonDao;


  public MetadataCollectTaskResult queryByCollectTaskIdAndTaskId(
      String metadataCollectTaskId, String processInstanceId) {
    List<TaskInstanceDto> list = commonDao.getTaskInstanceByProcessInstanceId(processInstanceId);
    if (CollectionUtils.isEmpty(list)) {
      throw new BusinessException("当前流程实例没有产生任务实例");
    }
    return this.mapper.queryByCollectTaskIdAndTaskId(metadataCollectTaskId, list.get(0).getId());
  }
}
